<template>
    <div>
        <scroll-view scroll-x class="bg-white nav text-center">
            <view :class="'cu-item ' + (wall === 1 ? 'text-blue cur' : '')" @tap="tabSelect" data-id="1">组织列表</view>
            <view :class="'cu-item ' + (wall === 2 ? 'text-blue cur' : '')" @tap="tabSelect" data-id="2">我的组织</view>
            <view class="cu-item" @tap="apply">建立组织</view>
        </scroll-view>
        <div v-if="wall === 1">
            <div class="row solid-bottom" v-for="(association) in associationList">
                <div class="col-md-12 list_warp" :data-id="association.association_id" @tap="goToDetail">
                    <div class="avatar_wrap">
                        <img class="cu-avatar xl round margin-left icon" :src="association.logo">
                    </div>
                    <div class="ad_warp">
                        <h1>{{ association.association_name }}</h1>
                        <div class="des_warp">{{ association.description }}</div>
                    </div>
                </div>
            </div>
        </div>
        <div v-if="wall === 2">
            <div class="row solid-bottom" v-for="(association) in myAssociationList">
                <div class="col-md-12 list_warp" :data-id="association.association_id" @tap="goToDetail">
                    <div class="avatar_wrap">
                        <img class="cu-avatar xl round margin-left icon" :src="association.logo">
                    </div>
                    <div class="ad_warp">
                        <h1>{{ association.association_name }}</h1>
                        <div class="des_warp">{{ association.description }}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

const app = getApp();

export default {
    data() {
        return {
            associationList: [{
                association_name: '',
                description: '',
                logo: '',
                association_id: '',
            }],
            myAssociationList: [{
                association_name: '',
                description: '',
                logo: '',
                association_id: '',
            }],
            wall: 1,
        }
    },
    onUnload() {
		// uni.reLaunch({
		// 	url:"/pages/home/home"
		// })
        // uni.switchTab({
        // 	url: '/pages/home/home'
        // });
		
		// uni.navigateBack({
		// 	delta: 1
		// });
		
    },
	
	onBackPress() {
		// uni.reLaunch({
		// 	url:"../../pages/home/home"
		// })
		console.log("执行返回");
		
		// uni.navigateTo({
		// 	url:'../../pages/home/home'
		// });
		
		uni.reLaunch({
			url: '../../pages/home/home'
		});
		// uni.navigateBack({
		// 	delta: 1
		// });
		
	},
	
    onLoad: function () {
        this.getAssociationList();
        this.getMyAssociationList();
    },
    onPullDownRefresh: function () {
        this.getAssociationList();
        this.getMyAssociationList();
        uni.stopPullDownRefresh();
    },
    methods: {
        tabSelect(e) {
            let id = e.currentTarget.dataset.id;
            id = parseInt(id);
            this.setData({
                wall: id,
            });
        },
        getAssociationList() {
            let that = this;
            this.$myFunction.getData(app.globalData.ApiUrl + '/api/Android/getAssociationList', {
                SafeCode: uni.getStorageSync('SafeCode')
            }).then(res => {
                if (res.code == 1) {
                    that.setData({
                        associationList: res.data
                    });
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none'
                    });
                }

            });
        },
        getMyAssociationList() {

            let that = this;
            this.$myFunction.getData(app.globalData.ApiUrl + '/api/Android/getMyAssociationList', {
                SafeCode: uni.getStorageSync('SafeCode')
            }).then(res => {

                if (res.code == 1) {
                    that.setData({
                        myAssociationList: res.data
                    });
                } else {
                    uni.showToast({
                        title: res.msg,
                        icon: 'none'
                    });
                }

            });
        },
        /**
         * 跳转到详情页
         * @param e
         */
        goToDetail(e) {
            let id = e.currentTarget.dataset.id;
            uni.navigateTo({
                url: '/pages/association/detail/detail?id=' + id
            });
        },
        /**
         * 跳转到创建页
         * @param e
         */
        apply() {
            uni.navigateTo({
                url: '/pages/association/apply/apply'
            });
        }
    }
}
</script>

<style scoped>
.test {
    border: solid;
    border-color: red;
}

.list_warp {

    background-color: white;
}

.avatar_wrap {
    width: 100px;
    float: left;
    line-height: 1;

}

.icon {
    border: 1px solid #e6e6e6;
}

.ad_warp {
    margin-left: 110px;
    text-align: left;
}

.des_warp {
    margin-top: 20px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 18px;
    font-weight: 500;
    white-space: nowrap;
}

</style>